package study.thread.basic;

/**
 * 通过继承Thread类创建线程
 * @author Aric(taowei)
 *
 */
public class MyThread extends Thread {
	private int counter = 1;
	private int number;
	
	//构造器
	public MyThread(int num) {
		number = num;
		System.out.println("创建线程 ==> "+number);
	}
	
	//重写Tread类的run方法
	public void run() {
		
		while (true) {
			++counter;
			if (counter > 6) {
				System.out.println("counter = "+counter+" > 6 退出while循环，线程"+this.number+"执行run方法结束");
				return;
			}
			System.out.println("线程"+this.number+"的计数器 ==> "+counter);
		}
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 6; i++) {
			new MyThread(i+1).start();
		}
	}
}
